<template>
	<view>
		<view class="mt-5" v-if="u_loadmore">
			<u-loadmore status="loading" icon-type="circle" />
		</view>
		<view v-else>
			<view class="" v-if="User.is_merchant">
				<!-- 商品分类 -->
				<radio-group>
					<view class="rounded-20 m-2 bg-white">
						<view class="d-flex j-sb pl-3 a-center h_110"  @click="top_level">
							<radio color="#fc3939" :checked="item.cat_id === current" />
							<view class="flex-1 d-flex j-sb a-center h_100 border-bottom">
								<view class="ml-1 font-md">顶级分类</view>
							</view>
						</view>
						<label v-for="(item,index) in oneGoods" :key="index" @click="one_goods(item)">
							<view class="d-flex j-sb pl-3 a-center h_110"  >
								<radio color="#fc3939" :value="item.cat_name" :checked="item.cat_id == current" />
								<view class="flex-1 d-flex j-sb a-center h_100 border-bottom">
									<view class="ml-1 font-md">{{item.cat_name}}</view>
									<view class="pr-3">
										<u-icon name="arrow-right" color="#999" size="28" @tap.stop="selection_class(item)" v-if="item.iconshow"></u-icon>
									</view>
								</view>
							</view>
						</label>
					</view>
				</radio-group>
			</view>
			<view class="" v-else>
				<!-- 平台分类 -->
				<radio-group >
					<view class="rounded-20 m-2 bg-white" >
						<view class="d-flex j-sb pl-3 a-center h_110"  @click="top_level">
							<radio color="#fc3939" :checked="item.cat_id === current" />
							<view class="flex-1 d-flex j-sb a-center h_100 border-bottom">
								<view class="ml-1 font-md">顶级分类</view>
							</view>
						</view>
						<label v-for="(item,index) in oneClazz" :key="index"  @click="one_goods(item)" >
							<view class="d-flex j-sb pl-3 a-center h_110">
								<radio color="#fc3939" :value="item.cat_name" :checked="item.cat_id == current" />
								<view class="flex-1 d-flex j-sb a-center h_100 border-bottom">
									<view class="ml-1 font-md">{{item.cat_name}}</view>
									<view class="pr-3">
										<u-icon name="arrow-right" color="#999" size="28" @tap.stop="selection_class(item)" v-if="item.iconshow"></u-icon>
									</view>
								</view>
							</view>
						</label>
					</view>
				</radio-group>
			</view>	
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				goodsClazz:[], // 商品分类列表
				oneGoods:[], // 1级商品分类

				
				terraceClazz:[], // 平台分类
				oneClazz:[], // 1级平台分类
				tabIndex:0,  // 标识符tab
				goods_cat_id:"" ,// 二级parent_id
				current:"",
				boardList:[],
				boarIndex:"",
				User:"",
				category_id:"",
				u_loadmore:true, // 加载中
			}
		},
		onLoad(e) {
			this.category_id=e.category_id
			this.current=e.category_id
			this.$H.post("admin/user/userinfo").then(res=>{
				this.User=res.data
				if(this.User.is_merchant){
					console.log(1)
					// 商品分类 merchant merchant
					this.$H.post("admin/merchant/goods/merchant/category").then(res=>{
						this.u_loadmore=false 
						this.goodsClazz=res.data
						this.goodsClazz.filter((item,index)=>{
								return item.icon_show=false
						})
						this.oneGoods=this.goodsClazz.filter((item,index)=>{
							if(item.parent_id==0){
								return item
							}
						})
						
						this.oneGoods.filter((item,index)=>{
							this.goodsClazz.forEach((v,i)=>{
								if(item.cat_id==v.parent_id){
									return item.iconshow=true
								}
							})
						})
					})
				}else{
					console.log(1)
					// 平台分类
					this.$H.post("admin/merchant/goods/category").then(res=>{
						this.u_loadmore=false 
						this.terraceClazz=res.data
						this.terraceClazz.filter((item,index)=>{
								return item.icon_show=false
						})
						
						this.oneClazz=this.terraceClazz.filter((item,index)=>{
							if(item.parent_id==0){
								return item
							}
						})
						this.oneClazz.filter((item,index)=>{
							this.terraceClazz.forEach((v,i)=>{
								if(item.cat_id==v.parent_id){
									return item.iconshow=true
								}
							})
						})
					})
				}
			})
			this.boarIndex=e.category_id
		},
		methods: {
			// 编辑商品分类页面
			selection_class(item){
				uni.navigateTo({
					url:`/pages/goods-class-selection/goods-class-selection?cat_id=${item.cat_id}&category_id=${this.category_id}`
				})
			},
			one_goods(item){
				this.current=item.cat_id
				uni.navigateBack({
					delta:1
				})
				var globalData = getApp().globalData.closeLists;
				getApp().globalData.closeLists= item; 
			},
			top_level(){
				uni.navigateBack({
					delta:1
				})
			}
		}
	}
</script>

<style>
</style>
